//
//  YDVerticalStockButtonOptionView.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/27.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDVerticalStockButtonOptionView.h"

@interface YDVerticalStockButtonOptionView()

/**
 股票交易按钮
 */
@property (nonatomic , weak) SYNoHeightedButton *stockButton;

/**
 期权交易按钮
 */
@property (nonatomic , weak) SYNoHeightedButton *optionButton;


/**
 更换股票按钮
 */
@property (nonatomic , weak) SYNoHeightedButton *changeButton;


/**
 发布按钮
 */
@property (nonatomic , weak) SYNoHeightedButton *publishButton;


@end

@implementation YDVerticalStockButtonOptionView

-(void)setOptionViewStyle:(SYVerticalStockButtonOptionViewStyle)optionViewStyle
{
    _optionViewStyle = optionViewStyle;
    /*
     SYVerticalStockButtonOptionViewStyle0,//0   //正常显示股票和期权交易
     SYVerticalStockButtonOptionViewStyle1,//1   //活动，显示发布和更换股票
     SYVerticalStockButtonOptionViewStyle2,//    //只显示股票交易按钮
     SYVerticalStockButtonOptionViewStyle3,      //只显示期权交易按钮
     
     */
    if (optionViewStyle == SYVerticalStockButtonOptionViewStyle0) {
        
        
        self.stockButton.hidden = NO;
        self.optionButton.hidden = NO;
        self.changeButton.hidden = YES;
        self.publishButton.hidden = YES;
        
        
    }else if (optionViewStyle == SYVerticalStockButtonOptionViewStyle1){
        
        self.stockButton.hidden = YES;
        self.optionButton.hidden = YES;
        self.changeButton.hidden = NO;
        self.publishButton.hidden = NO;
        
    }else if (optionViewStyle == SYVerticalStockButtonOptionViewStyle2){
        
        self.stockButton.hidden = NO;
        self.optionButton.hidden = YES;
        self.changeButton.hidden = YES;
        self.publishButton.hidden = YES;
        [self.optionButton setTitle:@"股票交易" forState:UIControlStateNormal];
        
    }else if (optionViewStyle == SYVerticalStockButtonOptionViewStyle3){
        
        self.stockButton.hidden = YES;
        self.optionButton.hidden = NO;
        self.changeButton.hidden = YES;
        self.publishButton.hidden = YES;
        [self.optionButton setTitle:@"策略申购" forState:UIControlStateNormal];
    }
    

    
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self stockButton];
        [self optionButton];
        [self changeButton];
        [self publishButton];
    }
    return self;
}


+(instancetype)verticalStockButtonOptionViewWithButtonOptionViewStyle:(SYVerticalStockButtonOptionViewStyle)optionViewStyle
{
    YDVerticalStockButtonOptionView *optionView = [[YDVerticalStockButtonOptionView alloc] init];
    optionView.optionViewStyle = optionViewStyle;
    return optionView;
}


-(SYNoHeightedButton *)stockButton
{
    if (_stockButton == nil) {
        SYNoHeightedButton *stockButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:stockButton];
        stockButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        
        [stockButton setTitle:@"股票交易" forState:UIControlStateNormal];
        
        [stockButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        stockButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [stockButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:Orange]] forState:UIControlStateNormal];
        stockButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [stockButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.top.equalTo(self);
            make.width.equalTo(@(rate375(74)));
        }];
        stockButton.layer.cornerRadius = 3.0f;
        stockButton.layer.masksToBounds = YES;
        [stockButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        _stockButton = stockButton;
    }
    return _stockButton;
}

-(SYNoHeightedButton *)optionButton
{
    if (_optionButton == nil) {
        SYNoHeightedButton *optionButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:optionButton];
        optionButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        
        [optionButton setTitle:@"策略申购" forState:UIControlStateNormal];
        
        [optionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        optionButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [optionButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:Orange]] forState:UIControlStateNormal];
        optionButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [optionButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.top.equalTo(self);
            make.width.equalTo(@(rate375(74)));
        }];
        optionButton.layer.cornerRadius = 3.0f;
        optionButton.layer.masksToBounds = YES;
        [optionButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        _optionButton = optionButton;
    }
    return _optionButton;
}

-(SYNoHeightedButton *)changeButton
{
    if (_changeButton == nil) {
        SYNoHeightedButton *changeButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:changeButton];
        changeButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        
        [changeButton setTitle:@"更换股票" forState:UIControlStateNormal];
        [changeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        changeButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [changeButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:frenchBlue]] forState:UIControlStateNormal];
    
        changeButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [changeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.top.equalTo(self);
            make.width.equalTo(@(rate375(74)));
        }];
        changeButton.layer.cornerRadius = 3.0f;
        changeButton.layer.masksToBounds = YES;
        [changeButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        _changeButton = changeButton;
    }
    return _changeButton;
}

-(SYNoHeightedButton *)publishButton
{
    if (_publishButton == nil) {
        SYNoHeightedButton *publishButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:publishButton];
        publishButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        
        [publishButton setTitle:@"发布" forState:UIControlStateNormal];
        
        [publishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        publishButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [publishButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:Orange]] forState:UIControlStateNormal];
        publishButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [publishButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.top.equalTo(self);
            make.width.equalTo(@(rate375(74)));
        }];
        publishButton.layer.cornerRadius = 3.0f;
        publishButton.layer.masksToBounds = YES;
        [publishButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
        _publishButton = publishButton;
    }
    return _publishButton;
}



-(void)buttonClick:(SYNoHeightedButton *)button
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(verticalStockButtonOptionView:withButtonTitle:)]) {
        [self.delegate verticalStockButtonOptionView:self withButtonTitle:button.titleLabel.text];
    }
}
@end
